import { Injectable } from '@nestjs/common'
import { CreateCategoryDto } from './dto/create-category.dto'
import { UpdateCategoryDto } from './dto/update-category.dto'
import { PrismaService } from '@/prisma/prisma.service'
import { QueryCategoryDto } from '@/category/dto/query-category.dto'

@Injectable()
export class CategoryService {
  constructor(private prisma: PrismaService) {}

  create(createCategoryDto: CreateCategoryDto) {
    return 'This action adds a new category'
  }

  async findAll(query: QueryCategoryDto) {
    const category = await this.prisma.category.findMany({
      take: +query.pageSize,
      skip: (+query.pageNo - 1) * +query.pageSize,
      where: {
        title: query.title,
      },
    })
    return {
      total: await this.prisma.category.count(),
      row: category,
    }
  }

  findOne(id: number) {
    return `This action returns a #${id} category`
  }

  update(id: number, updateCategoryDto: UpdateCategoryDto) {
    return `This action updates a #${id} category`
  }

  remove(id: number) {
    return `This action removes a #${id} category`
  }
}
